package game;

import player.Player;
import validation.Evaluator;

/**
 * GameRound controls the flow of each each round. It controls the logic between
 * successive turns. <br>
 * <br>
 * A round will end as soon as a player has a higher hand than all the other
 * players.
 * 
 * 
 * @version 2.2.0
 * 
 */
public class GameRound {

	private Player[] players;
	private Player biggestPlayer;
	private Player currentPlayer;
	private GameTurn currentTurn;

	public GameRound(Player[] players, Player startPlayer, Evaluator evaluator) {
		this.players = players;
		currentPlayer = startPlayer;
		evaluator.newRound();
		biggestPlayer = null;
	}

	/**
	 * return current turn as next turn
	 * 
	 * @return currentTurn
	 */
	public GameTurn NextTurn() {
		if (currentTurn != null) {
			currentPlayer = getNextPlayer();
		}

		currentTurn = new GameTurn(currentPlayer);
		return currentTurn;
	}

	/**
	 * Check if the round is end
	 * 
	 * @return
	 */
	public boolean isEndOfRound() {
		if (currentTurn.isBiggerPlay())
			biggestPlayer = currentPlayer;
		return (biggestPlayer == getNextPlayer());
	}

	/**
	 * return next player
	 * @return
	 */
	public Player getNextPlayer() {
		int val = (currentPlayer.getID() + 1) % 3;
		return players[val];
	}

	/**
	 * return the biggest player
	 * @return
	 */
	public Player getBiggestPlayer() {
		return biggestPlayer;
	}

}
